#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n, m, t, ret;
struct ty {
	string l, r;
}a[N];

bool cmp(ty x, ty y ) {
	return x.l < y.l;
}

signed main() {
	IOS;
	cin >> n;
	for(int i = 1; i <= n; ++ i ) {
		string x;
		cin >> a[i].l >> x >> a[i].r;
	}
	sort(a + 1, a + n + 1, cmp);
	a[0].r = "00:00:00";
	a[n + 1].l = "23:59:59";
	
	for(int i = 0; i <= n; ++ i ) {
		if(a[i].r != a[i + 1].l) {
			cout << a[i].r + " - " + a[i + 1].l << endl;
		}
//		cout << a[i].l << " " << a[i].r << endl;
	}
	return 0;
}


